Finding bugs in your translator

If the translateMarkup() function contains certain types of errors, the translator loads properly, but it fails silently when invoked. Although failing silently prevents Dreamweaver from becoming unstable, it can hinder development, especially when trying to find one small syntax error in 10 or 20 or 30 lines of code.

If your translator fails, one debugging method that works well is to turn the translator into a command, as follows:

1 Copy the entire contents of the translator file to a new document, and save it in the Configuration/Commands folder inside the Dreamweaver application folder.
2 At the top of the document, between the SCRIPT tags, add the following function:
function commandButtons(){
  return new Array( "OK","translateMarkup(dreamweaver.getDocumentPath('document'),
dreamweaver.getSiteRoot(),
dreamweaver.getDocumentDOM().documentElement.outerHTML);
window.close()", "Cancel", "window.close()");
}
3 At the end of the translateMarkup() function, comment out the return whateverTheReturnValueIs line and replace it with dreamweaver.getDocumentDOM().documentElement.outerHTML = whateverTheReturnValueIs. For example:
  // return theCode;
  dreamweaver.getDocumentDOM().documentElement.outerHTML = theCode;
} 
/* end of translateMarkup() */
4 In the BODY of the document, add a form with no input fields. For example:
<body><form>Hello.
</form></body>
5 Restart Dreamweaver, and then choose your "translator command" from the Commands menu. When you click OK, the translateMarkup() function is called, simulating translation.
If you see no error message and translation still fails, you probably have a logic error in your code.
6 Add alert() statements in strategic spots throughout the translateMarkup() function so you can make sure you're hitting the proper branches, and so you can check the values of variables and properties at different points. For example:
for (var i=0; i< foo.length; i++){
  alert("we're at the top of the foo.length array, and the value of i is " + i);
  /* rest of loop */
}
7 After adding in the alert() statements, choose your command from the Commands menu, click Cancel, and then choose it again. This reloads the command file, incorporating your changes.